<?php

/**
 * CCoreBaseFollowersCollection
 *
 * @author Usenko Timur <usenko.timur@gmail.com>
 * @package base
 */

CCore::Using('base.collection');

/**
 * @package base
 */
class CCoreBaseFollowersCollection extends ACoreBaseCollection
{
	const INFO = 1;
	const ERROR = 2;
	const WARNING = 4;
	const NOTICE = 8;

	/**
	 * @var array
	 */
	private $_aPrefixs;

	/**
	 * @var array
	 */
	private $_aSecretValues;

	/**
	 * @return CCoreBaseFollowersCollection
	 */
	public function __construct()
	{
		parent::__construct();

		$this->_aSecretValues = array();
		$this->_aPrefixs = array(
			self::INFO => 'INFO',
			self::ERROR => 'ERROR',
			self::WARNING => 'WARNING',
			self::NOTICE => 'NOTICE'
		);
	}

	/**
	 * @param string $sInfoPrefix
	 * @param string $sErrorPrefix
	 * @param string $sWarningPrefix
	 * @param string $sNoticePrefix
	 * @return void
	 */
	public function InitPrefixs($sInfoPrefix, $sErrorPrefix, $sWarningPrefix, $sNoticePrefix)
	{
		CCore::CheckTypes(array('$sInfoPrefix', '$sErrorPrefix', '$sWarningPrefix', '$sNoticePrefix'));

		$this->_aPrefixs = array(
			self::INFO => $sInfoPrefix,
			self::ERROR => $sErrorPrefix,
			self::WARNING => $sWarningPrefix,
			self::NOTICE => $sNoticePrefix
		);
	}
	
	/**
	 * @param array $aSecretValues
	 * @return void
	 */
	public function SetSecretValues(array $aSecretValues)
	{
		$this->_aSecretValues = array();
		foreach ($aSecretValues as $sItemValue)
		{
			if (!empty($sItemValue))
			{
				$this->_aSecretValues[] = $sItemValue;
			}
		}
	}

	/**
	 * @param ICoreBaseFollowers $oFollower
	 * @return void
	 */
	public function Add(ICoreBaseFollowers $oFollower)
	{
		CCore::CheckTypes(array('$oFollower'));

		parent::Add($oFollower);
	}

	/**
	 * @param string $sDesc
	 * @param int $iDescType
	 * @return void
	 */
	public function Write($sDesc, $iDescType = self::INFO)
	{
		CCore::CheckTypes(array('$sDesc', '$iDescType'));

		$nsPrefix = isset($this->_aPrefixs[$iDescType]) ? $this->_aPrefixs[$iDescType] : null;
		$aFollowers =& $this->GetAsArray();
		foreach ($aFollowers as /* @var $oFollower ICoreBaseFollowers */ &$oFollower)
		{
			$oFollower->Write($sDesc, $iDescType, $nsPrefix, $this->_aSecretValues);
		}
	}
}
